//
//  DownloadingViewController.m
//  MXClassroom
//
//  Created by 你个LB on 16/9/11.
//  Copyright © 2016年 你个LB. All rights reserved.
//

#import "DownloadingViewController.h"

@interface DownloadingViewController ()

@end

@implementation DownloadingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initDataSource];
    
    [self initTableView];
    
}

// 单元格数据
- (void)initDataSource{
    
    NSMutableArray * models = [NSMutableArray array];
    NSArray * data = @[@{@"headImg":@"icon_main_recommend_science_normal.png",
                         @"title":@"标题",
                         @"teacher":@"我佛慈悲",
                         @"teachTime":@"1天前",
                         @"fileSize":@"3.4",
                         @"downloadState":@"Downloading",
                         @"downloadProgress":@"0.7"},
                       @{@"headImg":@"icon_main_recommend_science_normal.png",
                         @"title":@"标题2",
                         @"teacher":@"我佛慈悲2",
                         @"teachTime":@"2天前",
                         @"fileSize":@"3.4",
                         @"downloadState":@"WaitDownload",
                         @"downloadProgress":@"0.0"}];
    
    for (int i = 0; i < 2; i ++) {
        DownloadModel * download = [[DownloadModel alloc] initWithContentDic:data[i]];
        [models addObject:download];
    }
    _dataList = models;
}

- (void)initTableView{
    UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, kScreen_height) style:UITableViewStyleGrouped];
    tableView.dataSource = self;
    tableView.delegate = self;
    [self.view addSubview:tableView];
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _dataList.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DownloadTableViewCell * cell = [DownloadTableViewCell cellWithTableView:tableView];
    cell.download = _dataList[indexPath.section];
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 12;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 86 + 30;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
